<div class="panel-body" id="ruleform" style="background: #FFFFFF;">
	<div class="row " style="padding-top: 10px">
		<div class="col-md-1 col-xs-1 col-lg-1">
			<div style="float: right"><span>旧密码</span></div>
		</div>
		<div class="col-md-10 col-xs-10 col-lg-10">
			<div class="form-group" style="border: none;">
				<input type="password" class="form-control" id="oldPassWord" name="oldPassWord" style="width: 160px;" />
				<span style="color:darkred;display: inline;float: left;" id="oldInfo"></span>
			</div>
		</div>
	</div>
	<div class="row " style="padding-top: 10px">
		<div class="col-md-1 col-xs-1 col-lg-1">
			<div style="float: right"><span>新密码</span></div>
		</div>
		<div class="col-md-10 col-xs-10 col-lg-10">
			<div class="form-group" style="border: none;">
				<input type="password" class="form-control" onkeyup="CheckPassWord()" id="newPassWord" name="newPassWord" style="width: 160px;" />
				<span style="color:darkred;display: inline;float: left;" id="newInfo">请输入8位至16位的，由有字母、特殊字符、数字组合的新密码！</span>
			</div>
		</div>
	</div>
	<div class="row " style="padding-top: 10px">
		<div class="col-md-1 col-xs-1 col-lg-1">
			<div style="float: right"><span>再次输入密码</span></div>
		</div>
		<div class="col-md-10 col-xs-10 col-lg-10">
			<div class="form-group" style="border: none;">
				<input type="password" class="form-control" id="nextNewPassWord" name="nextNewPassWord" style="width: 160px;" />
				<span style="color:darkred;display: inline;float: left;" id="nextInfo"></span>
			</div>
		</div>
	</div>
	<div class="row" style="padding-top: 10px;margin-bottom: 20px">
		<div class="col-md-1 col-xs-1 col-lg-1">
		</div>
		<div class="col-md-11 col-xs-11 col-lg-11">
			<a class="btn btn-info" onclick="save()">保存</a>
		</div>
	</div>
</div>

<script>
	var bool = false;

	function CheckPassWord() {
		var password = $("#newPassWord").val();
		var info = checkpassword(password);
		if(info != true) {
			$("#newInfo").html(info);
		} else {
			$("#newInfo").html('');
		}
	}

	function save() {
		//开始传值请求
		var OldPass = $('#oldPassWord').val();
		var NewPass = $('#newPassWord').val();
		var newpwdagain = $('#newPassWord').val();
		if(!bool) {
			debugger
			$("#newInfo").html("请输入8位至16位的，由有字母、特殊字符、数字组合的新密码！");
			$("#nextInfo").html("两次密码不一样");
		} else if(OldPass == "") {
			$("#oldInfo").html("旧密码不能为空");
		} else if(NewPass == "") {
			$("#newInfo").html("新密码不能为空");
		} else if(newpwdagain == "") {
			$("#nextInfo").html("请再次输入密码");
		} else if(NewPass != newpwdagain) {
			$("#nextInfo").html("两次密码不一样");
		} else {
			$.ajax({
				url: GLOBAL.URL + "/sys/user/password",
				data: {
					"password": OldPass,
					"newPassword": NewPass
				},
				type: 'POST',
				dataType: "json",
				ContentType: 'application/json',
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				success: function(result) {
					if(result != null) {
						if(result.code == 0) {
							var onlyChoseAlert = simpleAlert({
								"content": "密码修改成功，请重新登录！",
								"buttons": {
									"确定": function() {
										onlyChoseAlert.close();
										window.location.href = "login.html";
									}
								}
							});
						} else if(result.code == "403") {
							AlertInfo("操作失败！" + result.msg);
							window.location.href = "login.html";
						} else {
							AlertInfo("请求失败！" + result.msg);
						}
					}
				}
			});
		}
	}

	function checkpassword(v) {
		var numasc = 0;
		var charasc = 0;
		var otherasc = 0;
		if(0 == v.length) {
			return "密码不能为空";
		} else if(v.length < 8 || v.length > 16) {
			return "密码至少8个字符,最多16个字符";
		} else {
			for(var i = 0; i < v.length; i++) {
				var asciiNumber = v.substr(i, 1).charCodeAt();
				if(asciiNumber >= 48 && asciiNumber <= 57) {
					numasc += 1;
				}
				if((asciiNumber >= 65 && asciiNumber <= 90) || (asciiNumber >= 97 && asciiNumber <= 122)) {
					charasc += 1;
				}
				if((asciiNumber >= 33 && asciiNumber <= 47) || (asciiNumber >= 58 && asciiNumber <= 64) || (asciiNumber >= 91 && asciiNumber <= 96) || (asciiNumber >= 123 && asciiNumber <= 126)) {
					otherasc += 1;
				}
			}
			if(0 == numasc) {
				return "密码必须含有数字";
			} else if(0 == charasc) {
				return "密码必须含有字母";
			} else if(0 == otherasc) {
				return "密码必须含有特殊字符";
			} else {
				bool = true;
				return true;

			}
		}
	};
</script>